package zfes.snowier.projects.sample.biz.util;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import zfes.snowier.projects.sample.biz.model.ArticleRaw;
public class ElasticUtil {
	
	 public static Map<String, Object> toDocument(ArticleRaw articleRaw) {
	        Map<String, Object> map = new HashMap<String, Object>();
	        if (articleRaw != null) {
	        	
	        	 map.put("title",articleRaw.getTitle());
	        	 map.put("content",articleRaw.getContent());
	        	 map.put("author",articleRaw.getAuthor());
	        	
	        	 map.put("pub_stamp",articleRaw.getPubStamp());
	        	 map.put("crawl_stamp",articleRaw.getCrawlStamp());
	        	
	        	 map.put("crawl_date",new SimpleDateFormat("yyyy-MM-dd").format(articleRaw.getCrawlDate()==null?new Date():articleRaw.getCrawlDate()));
	        	 map.put("pub_date",new SimpleDateFormat("yyyy-MM-dd").format(articleRaw.getPubDate()==null?new Date():articleRaw.getPubDate()));
	        	
	        	 map.put("pub_datetime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(articleRaw.getPubDatetime()==null?new Date():articleRaw.getPubDatetime()));
	        	 map.put("crawl_datetime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(articleRaw.getCrawlDatetime()==null?new Date():articleRaw.getCrawlDatetime()));
	        	
	        	 map.put("from_ip",articleRaw.getFromIp());
	        	 map.put("from_url",articleRaw.getFromUrl());
	        	 map.put("media_type",articleRaw.getMediaType());
	        	 map.put("spider_name",articleRaw.getSpiderName());
	        	 map.put("classid",articleRaw.getClassid());
	        	 map.put("negative",articleRaw.getNegative());
	        	 map.put("positive",articleRaw.getPolarity());
	        	 map.put("polarity",articleRaw.getPolarity());
	         
	        }

	        return map;
	    }
	
    
    
}
